//: C14:Ccright.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Correctly synthesizing the CC
#include <iostream>
using namespace std;

class Parent
{
    int i;
public:
    Parent(int ii) : i(ii) {
        cout << "Parent(int ii)\n";
    }
    Parent(const Parent& b) : i(b.i) {
        cout << "Parent(Parent&)\n";
    }
    Parent() :i(0) {
        cout << "Parent()\n";
    }
    friend ostream&
    operator<<(ostream& os, const Parent& b) {
        return os << "Parent: " << b.i << endl;
    }
};

class Member
{
    int i;
public:
    Member(int ii) : i(ii) {
        cout << "Member(int ii)\n";
    }
    Member(const Member& m) : i(m.i) {
        cout << "Member(Member&)\n";
    }
    friend ostream&
    operator<<(ostream& os, const Member& m) {
        return os << "Member: " << m.i << endl;
    }
};

class Child : public Parent
{
    int i;
    Member m;
public:
    Child(int ii) : Parent(ii), i(ii), m(ii) {
        cout << "Child(int ii)\n";
    }
    friend ostream&
    operator<<(ostream& os, const Child& d) {
        return os << (Parent&)d << d.m
               << "Child: " << d.i << endl;
    }
};

int main()
{
    Child d(2);
    cout << "calling copy-constructor: " << endl;
    Child d2 = d; // Calls copy-constructor
    cout << "values in d2:\n" << d2;
} ///:~
